package com.gogowan.agroenterprise.widget.wheel;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.gogowan.agroenterprise.widget.wheel.TradeInfo;

public class XmlParserHandler2 extends DefaultHandler
{

	/**
	 * 存储所有的解析对象
	 */
	private ArrayList<TradeInfo> vocationAL = new ArrayList<TradeInfo>();
	private TradeInfo fTradeModel;
	private TradeInfo sTradeModel;

	public XmlParserHandler2()
	{

	}

	public ArrayList<TradeInfo> getDataList()
	{
		return vocationAL;
	}

	@Override
	public void startDocument() throws SAXException
	{
		// 当读到第一个开始标签的时候，会触发这个方法
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException
	{
		// 当遇到开始标记的时候，调用这个方法
		if (qName.equals("ftrade"))
		{
			fTradeModel = new TradeInfo();
			fTradeModel.setTradeName(attributes.getValue(0));
			fTradeModel.setTradeCode(attributes.getValue(1));
			fTradeModel.setChildList(new ArrayList<TradeInfo>());
		} else if (qName.equals("strade"))
		{
			sTradeModel = new TradeInfo();
			sTradeModel.setTradeName(attributes.getValue(0));
			sTradeModel.setTradeCode(attributes.getValue(1));
		}
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException
	{
		// 遇到结束标记的时候，会调用这个方法
		if (qName.equals("strade"))
		{
			fTradeModel.getChildList().add(sTradeModel);
		} else if (qName.equals("ftrade"))
		{
			vocationAL.add(fTradeModel);
		}
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException
	{
	}

}
